#encoding=utf8
'''
Created on Nov 10, 2014

@author: jingyang <jingyang@smalltreemedia.com>
'''
import json

from django.http.response import HttpResponse

from app_info.models import App
from iap_info.models import IapType


def get_iap_type(req):
    app = ""
    try:
        app = App.objects.get(id=req.REQUEST.get('id'))
        store = app.app_store
        res = [it.__unicode__() for it in IapType.objects.filter(store=store)] or ''
    except Exception, e:
        print e
        res = ''
    return HttpResponse(json.dumps({'res': res, 'bundle_id': app.get_full_bundle_id() if app else ""}),
        mimetype='application/json')
